﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;

namespace WindowsFormProject.Depo.AlisDetay
{
    public class AlisDetayProvider
    {
        private AlisDetayProvider()
        { }
        public static DataTable AlisDetayByDataTable(Int32 AlisNo)
        {
            DataBaseProvider MyDatabase = new DataBaseProvider();
            MyDatabase.AddInParameter("@AlisID", SqlDbType.Int, AlisNo);
            return MyDatabase.ExecuteDataTable("MySp_SelectAlisDetay", CommandType.StoredProcedure, "AlisDetay");
        }
        public static int KontrolEtAlisDetayUrun(Int32 AlisID,string UrunID)
        {
            int returnValue = 0;
            DataBaseProvider myDatabase = new DataBaseProvider();
            myDatabase.AddInParameter("@AlisID", SqlDbType.Int ,AlisID );
            myDatabase.AddInParameter("@UrunID", SqlDbType.NVarChar , UrunID);
            returnValue = Convert.ToInt32(myDatabase.ExecuteScalar("MySp_KontrolEtSatisDetayMalzeme", CommandType.StoredProcedure));
            return returnValue;
        }
        public static int InsertAlisDetay(DataRow MyDataRow)
        {
            int ReturnValue = 0;
            DataBaseProvider MyDatabase = new DataBaseProvider();
            MyDatabase.AddInParameter("@AlisID", SqlDbType.Int,Convert.ToInt32( MyDataRow["AlisID"]));
            MyDatabase.AddInParameter("@UrunID", SqlDbType.NVarChar , MyDataRow["UrunID"].ToString());
            MyDatabase.AddInParameter("@AlisDetayAdet", SqlDbType.Decimal,Convert.ToDecimal(MyDataRow["AlisDetayAdet"]) );
            MyDatabase.AddInParameter("@AlisDetayFiyat", SqlDbType.Money, Convert.ToDecimal(MyDataRow["AlisDetayFiyat"]));
            MyDatabase.AddInParameter("@AlisDetayKDVOrani", SqlDbType.Decimal, MyDataRow["AlisDetayKDVOrani"]);
            //MyDatabase.AddInParameter("@AlisDetayTarih", SqlDbType.DateTime, Convert.ToDateTime(MyDataRow["AlisDetayTarih"]));
            MyDatabase.AddInParameter("@AlisDetayTarih", SqlDbType.DateTime,DateTime.Now );
            MyDatabase.AddInParameter("@AlisDetayIskonto", SqlDbType.Decimal, Convert.ToDecimal(MyDataRow["AlisDetayIskonto"]));
            MyDatabase.AddInParameter("@AlisDetayAlisKuru", SqlDbType.Money , Convert.ToDecimal(MyDataRow["AlisDetayAlisKuru"]));
            MyDatabase.AddInParameter("@AlisDetayDovizi", SqlDbType.Money, Convert.ToDecimal(MyDataRow["AlisDetayDovizi"]));

            MyDatabase.AddOutParameter("@Sonuc", SqlDbType.Int);
            ReturnValue = Convert.ToInt32(MyDatabase.ExecuteNonQuery("MySp_InsertAlisDetay", CommandType.StoredProcedure, "@Sonuc"));
            //ReturnValue = Convert.ToInt32(MyDatabase.ExecuteNonQuery("MySp_InsertAlisDetay", CommandType.StoredProcedure));
            return ReturnValue;


        }
        public static int UpdateAlisDetay(DataRow MyDataRow)
        {
            int ReturnValue = 0;
            DataBaseProvider MyDatabase = new DataBaseProvider();
            MyDatabase.AddInParameter("@AlisID", SqlDbType.Int, Convert.ToInt32(MyDataRow["AlisID"]));
            MyDatabase.AddInParameter("@UrunID", SqlDbType.NVarChar, MyDataRow["UrunID"].ToString());
            MyDatabase.AddInParameter("@AlisDetayAdet", SqlDbType.Decimal, Convert.ToDecimal(MyDataRow["AlisDetayAdet"]));
            MyDatabase.AddInParameter("@AlisDetayFiyat", SqlDbType.Money, Convert.ToDecimal(MyDataRow["AlisDetayFiyat"]));
            MyDatabase.AddInParameter("@AlisDetayKDVOrani", SqlDbType.Decimal, MyDataRow["AlisDetayKDVOrani"]);
            //MyDatabase.AddInParameter("@AlisDetayTarih", SqlDbType.DateTime, Convert.ToDateTime(MyDataRow["AlisDetayTarih"]));
            //MyDatabase.AddInParameter("@AlisDetayTarih", SqlDbType.DateTime, DateTime.Now);
            MyDatabase.AddInParameter("@AlisDetayIskonto", SqlDbType.Decimal, Convert.ToDecimal(MyDataRow["AlisDetayIskonto"]));
            MyDatabase.AddInParameter("@AlisDetayAlisKuru", SqlDbType.Money, Convert.ToDecimal(MyDataRow["AlisDetayAlisKuru"]));
            MyDatabase.AddInParameter("@AlisDetayDovizi", SqlDbType.Money, Convert.ToDecimal(MyDataRow["AlisDetayDovizi"]));

            MyDatabase.AddOutParameter("@Sonuc", SqlDbType.Int);
            ReturnValue = Convert.ToInt32(MyDatabase.ExecuteNonQuery("MySp_UpdateAlisDetay", CommandType.StoredProcedure, "@Sonuc"));
            //ReturnValue = Convert.ToInt32(MyDatabase.ExecuteNonQuery("MySp_InsertAlisDetay", CommandType.StoredProcedure));
            return ReturnValue;


        }
        //public static int UpdateAlisDetay(DataGridViewRow MyRow)
        //{
        //    int ReturnValue = 0;
        //    DataBaseProvider MyDatabase = new DataBaseProvider();
        //    MyDatabase.AddInParameter("@AlisDetayNo", SqlDbType.BigInt, MyRow.Cells[0].Value);
        //    MyDatabase.AddInParameter("@AlisNo", SqlDbType.Int, MyRow.Cells[1].Value);
        //    MyDatabase.AddInParameter("@Tarih", SqlDbType.SmallDateTime, MyRow.Cells[2].Value);
        //    MyDatabase.AddInParameter("@MalzemeKodu", SqlDbType.BigInt, MyRow.Cells[3].Value);
        //    MyDatabase.AddInParameter("@AlisMiktari", SqlDbType.Decimal, MyRow.Cells[6].Value);
        //    MyDatabase.AddInParameter("@BirimFiyat", SqlDbType.Money, MyRow.Cells[7].Value);
        //    MyDatabase.AddInParameter("@Kdv", SqlDbType.Decimal, MyRow.Cells[8].Value, 5);
        //    MyDatabase.AddInParameter("@Iskonto1", SqlDbType.Decimal, MyRow.Cells[9].Value);
        //    MyDatabase.AddInParameter("@AlisTuru", SqlDbType.Int, MyRow.Cells[13].Value);
        //    MyDatabase.AddInParameter("@OGListeFiyati", SqlDbType.Money, MyRow.Cells[14].Value);
        //    MyDatabase.AddInParameter("@OGGelisFiyati", SqlDbType.Decimal, MyRow.Cells[15].Value);
        //    MyDatabase.AddInParameter("@OGIskontolar", SqlDbType.NVarChar, MyRow.Cells[16].Value, 50);
        //    MyDatabase.AddInParameter("@Iskonto2", SqlDbType.Decimal, MyRow.Cells[17].Value);
        //    MyDatabase.AddInParameter("@Iskonto3", SqlDbType.Decimal, MyRow.Cells[18].Value);
        //    MyDatabase.AddInParameter("@Iskonto4", SqlDbType.Decimal, MyRow.Cells[19].Value);
        //    MyDatabase.AddInParameter("@Iskonto5", SqlDbType.Decimal, MyRow.Cells[20].Value);

        //    MyDatabase.AddOutParameter("@Sonuc", SqlDbType.Int);
        //    ReturnValue = Convert.ToInt32(MyDatabase.ExecuteNonQuery("MySp_NewUpdateAlisDetay", CommandType.StoredProcedure, "@Sonuc"));
        //    return ReturnValue;
        //}
    }
}
